import { lazy } from "react";
import { createBrowserRouter, Navigate } from 'react-router-dom'

const Home = lazy(() => import('../pages/home'))
const Index = lazy(() => import('../pages/index'))
const Order = lazy(() => import('../pages/order'))
const User = lazy(() => import('../pages/user'))
const User1 = lazy(() => import('../pages/user/user1'))
const User2 = lazy(() => import('../pages/user/user2'))
const Error = lazy(() => import('../pages/404'))
//二级路由
export const menu = [
    {
        path: '/index',
        element: <Index />,
        title: '用户信息'
    },
    {
        path: '/order',
        element: <Order />,
        title: '订单'
    },
    {
        path: '/user',
        element: <User />,
        title: '角色',
        children: [
            {
                path: '/user/user1',
                element: <User1 />,
                title: '角色1',
            },
            {
                path: '/user/user2',
                element: <User2 />,
                title: '角色2',
            },
        ]
    },
]
//一级路由
const router = createBrowserRouter([
    {
        path: '/',
        element: <Navigate to="/index" />
    },
    {
        path: '/',
        element: <Home />,
        children: menu
    },
    {
        path:'*',
        element:<Error/>
    }
])
export default router